package com.caffeinatedbliss.nanowrimo.spike;

import com.caffeinatedbliss.nanowrimo.NanowrimoComputer;

import java.text.DecimalFormat;

/**
 * Created by IntelliJ IDEA.
 * User: PSHAWKE
 * Date: Dec 5, 2005
 * Time: 2:37:45 PM
 * To change this template use File | Settings | File Templates.
 */
public class PlainTextTabulator extends Tabulator {
  private DecimalFormat fiveDigits;

  public PlainTextTabulator() {
    fiveDigits = new DecimalFormat("00000");
  }

  public void tabulateResults(NanowrimoComputer computer) {
    writeHeader();

    int[] historyCounts = computer.getHistoryCounts();
    int[] wordcount = computer.getWordcount();
    int[] adjustedCount = computer.getAdjustedCount();
    int[] pace = computer.getPace();
    int[] paceExpected = computer.getPaceExpected();
    int[] expectedPerDayAmount = computer.getExpectedPerDayAmount();
    int[] expectedWordCount = computer.getExpectedWordCount();
    boolean[] outliers = computer.getOutliers();

    for (int i = 0; i < historyCounts.length; i++) {
      System.out.print("|  ");
      System.out.print(fiveDigits.format(historyCounts[i]) + "  ");
      System.out.print(fiveDigits.format(wordcount[i]) + "  |  ");
      System.out.print(fiveDigits.format(adjustedCount[i]) + "   |  ");
      System.out.print(fiveDigits.format(pace[i]) + "  ");
      System.out.print(fiveDigits.format(paceExpected[i]) + "  |  ");
      System.out.print(fiveDigits.format(expectedPerDayAmount[i]) + "  ");
      System.out.print(fiveDigits.format(expectedWordCount[i]) + "  |  ");
      System.out.print(outliers[i] ? "X" : " ");
      System.out.println("  |");
    }

    writeFooter();
  }

  private void writeHeader() {
    writeLine();
    System.out.println("|  ACTUAL WORDS  | ADJUSTED | ADJUSTED PACE  |  30-DAY PACE   | OUT |");
    writeLine();
  }

  private void writeFooter() {
    writeLine();
  }

  private void writeLine() {
    System.out.println("+----------------+----------+----------------+----------------+-----+");
  }
}
